package com.buer.storage.service.impl;

import com.buer.storage.dao.ProdCategoryDao;
import com.buer.storage.dto.*;
import com.buer.storage.entity.CategoryTwo;
import com.buer.storage.entity.Department;
import com.buer.storage.entity.Prod;
import com.buer.storage.entity.ProdCategory;
import com.buer.storage.service.ProdCategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

//装备分类管理
@Service
public class ProdCategoryServiceImpl implements ProdCategoryService {

    @Resource
    private ProdCategoryDao prodCategoryDao;

    //增加装备分类
    @Override
    public int add(ProdCategoryDto prodCategoryDto) {
        return prodCategoryDao.add(prodCategoryDto);
    }

    //删除装备分类
    @Override
    public int delete(int categoryId) {
        return prodCategoryDao.delete(categoryId);
    }

    //修改装备分类
    @Override
    public int update(ProdCategory prodCategory) {
        return prodCategoryDao.update(prodCategory);
    }

    //查询所有装备分类
    @Override
    public List<ProdCategory> select() {
        return prodCategoryDao.select();
    }

    //通过编号或者名字查询
    @Override
    public List<ProdCategory> selectByName(String categoryNumber, String categoryName) {
        return prodCategoryDao.selectByName(categoryNumber, categoryName);
    }

    @Override
    public List<CategorySelectDto> SelectTwo() {
        List<CategorySelectDto> categoryAll = prodCategoryDao.selectTwo();
        if (categoryAll.size() > 0) {
            for (int i = 0; i < categoryAll.size(); i++) {
                CategoryTwo[] twos = prodCategoryDao.selectAll(categoryAll.get(i).getCategoryId());
                if (twos.length > 0) {
                    categoryAll.get(i).setCategoryTwos(twos);
                }
            }
        }
        return categoryAll;
    }

    @Override
    public List<Prod> selectCategory(Integer categoryTwoId, String prodName) {
        List<Prod> prodList = prodCategoryDao.selectCategory(categoryTwoId, prodName);
        return prodList;
    }

    @Override
    public List<String> getChildName(Integer categoryId) {
        return prodCategoryDao.getChildName(categoryId);
    }


}
